package com.cn.ycy.aop.annation;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class AopTest {

  /**
   * 测试 after 和 before 两个通知
   */
  @Test
  public void test1() {
    AnnotationConfigApplicationContext annotationConfigApplicationContext =
            new AnnotationConfigApplicationContext(CompentScanConfig.class);

    String[] beanNamesForType
            = annotationConfigApplicationContext.getBeanNamesForType(Service.class);

    Service bean = annotationConfigApplicationContext.getBean(Service.class);

    bean.play();
  }

  /**
   * 测试 around 切面
   */
  @Test
  public void test2() {
    AnnotationConfigApplicationContext annotationConfigApplicationContext =
            new AnnotationConfigApplicationContext(CompentScanConfig.class);

    String[] beanNamesForType
            = annotationConfigApplicationContext.getBeanNamesForType(Service.class);

    Service bean = annotationConfigApplicationContext.getBean(Service.class);

    bean.playround();
  }

  /**
   * 测试 多个 通知 作用在 一个poincut 上的顺序
   */
  @Test
  public void test3() {
    AnnotationConfigApplicationContext annotationConfigApplicationContext =
            new AnnotationConfigApplicationContext(CompentScanConfig.class);

    String[] beanNamesForType
            = annotationConfigApplicationContext.getBeanNamesForType(Service.class);

    Service bean = annotationConfigApplicationContext.getBean(Service.class);
    bean.doWork();
  }

  /**
   *
   */
  @Test
  public void test4() {
    AnnotationConfigApplicationContext annotationConfigApplicationContext =
            new AnnotationConfigApplicationContext(CompentScanConfig.class);

    String[] beanNamesForType
            = annotationConfigApplicationContext.getBeanNamesForType(Service.class);

    Service bean = annotationConfigApplicationContext.getBean(Service.class);
    bean.doWork();
  }


}
